<?php
class Registermodel extends CI_Model {

	function registerInsert() {
		
		$username = $this->input->post ( 'username' );
		$email = $this->input->post ( 'email' );
		$name = $this->input->post ( 'name' );
		$country = $this->input->post ( 'country' );
		$phone = $this->input->post ( 'phone' );
		$website = $this->input->post ( 'website' );
		$sex = $this->input->post ( 'sex' );
		$education = $this->input->post ( 'education' );
		$education_branch = $this->input->post ( 'education_branch' );
		$education_name = $this->input->post ( 'education_name' );
		$education_degree = $this->input->post ( 'education_degree' );
		$newsletter = $this->input->post ( 'newsletter' );
		$terms = $this->input->post ( 'terms' );
		
		if ($this->input->post ( 'password' ) == $this->input->post ( 'repassword' )) {
			$password = md5 ( $this->input->post ( 'password' ) );
		} else {
			$this->session->set_flashdata ( 'mesaj', 'Şifreler birbiriyle uyuşmuyor!' );
			// redirect('main_page/index','refresh');
		}	
		
		
		$data = array(
				'user_name'=>$name,
				'user_username'=>$username,
				'user_mail'=>$email,
				'user_password'=>$password,
				'user_phone'=>$phone,
				'user_gender'=>$sex,
				'user_city'=>$country,
				'user_school'=> $education,
				'user_job'=>$education_name,
				'user_job_degree'=>$education_degree,
				'user_website'=>$website,
				'user_passport'=>0,
				'user_mail_validation'=>0,
				'user_register_date'=>mdate('%Y-%m-%d'),
				'newsletter_permission'=>$terms,
					
		);
		
		$this->db->select ( '*' );
		$this->db->where ( 'user_mail', $email );
		$this->db->limit ( 1 );
		$q = $this->db->get ( 'user' );
		
		if ($q->num_rows () == 1) {
			return false;
		}else {

			$this->db->insert('user',$data);
			return true;
		}
	}
}
?>